library(readstata13)
library(ggplot2)

NK= 
  theme_bw() +   
  theme(
  plot.title = element_text(size=13,vjust=1, hjust = 0.5, face = "bold"),
  axis.title.y = element_text(size = 12,vjust=1),
  axis.title.x = element_text(size = 12),
  axis.text.x=element_text(size=12),
  axis.text.y=element_text(size=11),
  strip.text.x = element_text(size = 12),
  panel.grid.minor = element_line(colour = NA),
  panel.grid.major=element_line(linetype="dotted", size=0.5),
  panel.grid.major.x = element_blank(), 
  panel.border = element_blank(),
  # axis.line=element_line(color = 'black'),
  axis.line.y=element_blank(),
  axis.line.x = element_line(color="black", size = .5), 
  # axis.line.y = element_line(color="black", size = .5),
  axis.line=element_line(),
  legend.title=element_blank(),
  # strip.text= element_text(face = "bold"), 
  legend.position = "none",
  strip.background=element_rect(colour="#f0f0f0",fill="#f0f0f0")
  # strip.background = element_rect(colour = NA, fill = NA)
)   

# predicted probability results are from the Stata output.


setwd("")
data <-read.dta13("sub1.dta")
data<-data[-9,]
data$x <-c(seq(.1,.8, by=.1))

p1=
  ggplot(data, aes(x=x, y=estimate))+
  theme_bw()+
  geom_line(size=1) + 
  geom_ribbon(aes(x =x, ymin=estimate-stderr*1.64 ,ymax=estimate+stderr*1.64), alpha=0.1, colour=NA)+
  ylab("Pr(coup attempt)")+ 
  xlab("")+
  ylim(0,.13)+
  scale_x_continuous(breaks = seq(.1, .8, by = .1))+  
  ggtitle("Interstate relationship")+
  NK
  
data <-read.dta13("sub2.dta")
data$x <-c(seq(.1,1.1, by=.1))

p2=
  ggplot(data, aes(x=x, y=estimate))+
  theme_bw()+
  geom_line(size=1) + 
  geom_ribbon(aes(x =x, ymin=estimate-stderr*1.64 ,ymax=estimate+stderr*1.64), alpha=0.1, colour=NA)+
  ylab("Pr(coup attempt)")+ 
  xlab("")+
  ylim(0,.13)+
  scale_x_continuous(breaks = seq(.1, 1.1, by = .1))+  
  ggtitle("Geopolitical competition")+
  NK

data <-read.dta13("sub3.dta")
data$x <-c(0,1)
data$x <- factor(data$x,levels = c(0,1),labels =  c("no","yes"))

p3=
  ggplot(data, aes(x=x, y=estimate))+
  theme_bw()+
  geom_point(size=2.5)+
  geom_linerange( aes(x=x, ymin = estimate-1.96*stderr, ymax = estimate+1.96*stderr), size=.8) +
  ylab("Pr(coup attempt)")+ 
  xlab("")+
  ylim(0,.13)+
  ggtitle("Strategic rivalry")+
  NK

data <-read.dta13("sub4.dta")
data$x <-c(0,1)
data$x <- factor(data$x,levels = c(0,1),labels =  c("no","yes"))

p4=
  ggplot(data, aes(x=x, y=estimate))+
  theme_bw()+
  geom_point(size=2.5)+
  geom_linerange( aes(x=x, ymin = estimate-1.96*stderr, ymax = estimate+1.96*stderr), size=.8) +
  ylab("Pr(coup attempt)")+ 
  xlab("")+
  ylim(0,.13)+
  ggtitle("Territorial claim")+
  NK

# pdf("sub.pdf",width=12, height=8)
# grid.arrange(p1,p2,p3,p4, ncol=2)
# dev.off()


png("sub.png",width=2400, height=1600,res = 300)
grid.arrange(p1,p2,p3,p4, ncol=2)
dev.off()

